﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing; // For Point 
using System.Windows.Forms;// For Panel

namespace RobotCleaner
{
    /// <summary>
    /// 障碍物类
    /// </summary>
    public class Obstacle
    {
        /// <summary>
        /// 障碍物的颜色
        /// </summary>
        private Color _O_Color = Color.SkyBlue;
        /// <summary>
        /// 障碍物X坐标
        /// </summary>
        private int _O_X = 100;  // 默认100
        /// <summary>
        /// 障碍物Y坐标
        /// </summary>
        private int _O_Y = 100;  // 默认100
        /// <summary>
        /// 障碍物 宽
        /// </summary>
        private int _O_width = 100; // 默认100
        /// <summary>
        /// 障碍物 高
        /// </summary>
        private int _O_height = 100; // 默认100

        /// <summary>
        /// 障碍物 X坐标
        /// </summary>
        public int O_X
        {
            get { return _O_X; }
            set { _O_X = value; }
        }
        /// <summary>
        /// 障碍物 Y坐标
        /// </summary>
        public int O_Y
        {
            get { return _O_Y; }
            set { _O_Y = value; }
        }
        /// <summary>
        /// 障碍物 宽
        /// </summary>
        public int O_width
        {
            get { return _O_width; }
            set { _O_width = value; }
        }
        /// <summary>
        /// 障碍物 高
        /// </summary>
        public int O_height
        {
            get { return _O_height; }
            set { _O_height = value; }
        }
        /// <summary>
        /// 障碍物类 构造函数初始化
        /// </summary>
        /// <param name="_p1"></param>
        /// <param name="_p2"></param>
        public Obstacle(Point _p1,Point _p2)
        {
            O_X = _p1.X;
            O_Y = _p1.Y;

            O_width = _p2.X - _p1.X;
            O_height = _p2.Y - _p1.Y;
        }
        /// <summary>
        /// 画障碍物
        /// </summary>
        /// <param name="_p1"></param>
        /// <param name="_p2"></param>
        public void drawObstacle(Point _p, Size _s,Panel panel)
        {
            try
            {
                Rectangle rec = new Rectangle(_p.X, _p.Y, _s.Width, _s.Height);
                using (Graphics g = panel.CreateGraphics())
                {
                    g.FillRectangle(new SolidBrush(_O_Color),
                           rec);
                    //// 对于大障碍物 画一个标签显示  Error!!!!!!!
                    //if (_s.Width * _s.Height > 20)
                    //{
                    //    Label text = new Label();
                    //    text.Size = new System.Drawing.Size(65, 12);
                    //    panel.Controls.Add(text);
                    //    text.AutoSize = true;
                    //    text.Location = new System.Drawing.Point(_p.X + _s.Width / 2, _p.Y + _s.Height / 2);
                    //    text.Text = "障碍物";
                    //    //MessageBox.Show("画障碍物三个字");
                    //}
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("绘制障碍物出错：" + ex.ToString());
            }
        }
    }
}
